package com.example.demo.Controller;


import com.example.demo.model.UserInfo;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RequestMapping("/param")
@RestController
public class ParamController {

    @RequestMapping("/p1")
    public String p1(String name){
        return "接收到参数,name "+ name;
    }

    @RequestMapping("p2")
    public String p2(Integer age){
        return "接收到年龄: age"+ age;
    }

    @RequestMapping("p4")
    public String p4(String name,Integer age){
        return " 接收到年龄: age " + age+" 接收到参数:name "+ name;

    }

    @RequestMapping("/p41")
    public String p41(HttpServletRequest request){
        String name = request.getParameter("name");
        Integer age = Integer.valueOf(request.getParameter("age"));

        return "接收到参数,age:" + age + ", name: "+ name;
    }

    @RequestMapping("/p6")
    public String p6(UserInfo user){
        return "user:" + user;
    }

    @RequestMapping("/p7")
    public String p7(@RequestParam(value = "username", required = false) String name){
        return " 接收到参数 name :" + name;
    }

    @RequestMapping("/p8")
    public String p8(String[] arr){
        return " 接收到参数 arr " + List.of(arr);
    }

    @RequestMapping("/p9")
    public String p9(@RequestParam List<String> list){
        return " 接收到参数 list :" + list;
    }

    @RequestMapping("/p10")
    public String p10(@RequestBody UserInfo user){
        return  " "+user;
    }

    @RequestMapping("/article/{articleId}")
    public String p11(@PathVariable("articleId") String articleId){
        return "articleId:   " + articleId;
    }

    @RequestMapping("/article/{articleId}/{name}")
    public String p12(@PathVariable("articleId") String id,@PathVariable String name){
        return "articleId: " + id + "name :" + name;
    }

    @RequestMapping("/p13")
    public String p13(@RequestPart("fileName")  MultipartFile file){
        System.out.println(file.getOriginalFilename());
        return  " 文件名称: " + file.getOriginalFilename();
    }





}
